﻿{include file='pub/header'/}
<title>充值列表</title>
</head>
<body>
<nav class="breadcrumb">{$breadNav} <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a href="javascript:;" onclick="charge_add('添加','{:url(\'Marketing/charge_add\')}','800','500')" class="btn btn-primary radius">
				<i class="Hui-iconfont">&#xe600;</i> 添加
			</a>
		</span>
	</div>
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="9">充值列表</th>
			</tr>
			<tr class="text-c">
				<th width="40">ID</th>
				<th width="150">充值金额</th>
				<th width="150">赠送金额</th>
				<th width="90">是否启用</th>
				<th width="120">操作</th>
			</tr>
		</thead>
		<tbody>
		{foreach $list as $item}
			<tr class="text-c">
				<td>{$item.id}</td>
				<td>{$item.money}</td>
				<td>{$item.given_money}</td>
				<td class="td-status">
					{if $item.status==1}
					<span class="label label-success radius">已启用</span>
					{else}
					<span class="label label-default radius">已禁止</span>
					{/if}
				</td>
				<td class="td-manage">
					{if $item.status == 1}
					<a style="text-decoration:none" onClick="charge_stop(this,'{$item.id}')" href="javascript:;" title="停用">
						<i class="Hui-iconfont">&#xe631;停用</i>
					</a>
					{else/}
					<a style="text-decoration:none" onClick="charge_start(this,'{$item.id}')" href="javascript:;" title="启用">
						<i class="Hui-iconfont">&#xe615;启用</i>
					</a>
					{/if}
					<a title="编辑" href="javascript:;" onclick="charge_edit('编辑活动','{:url(\'Marketing/charge_edit\', [\'id\'=>$item.id])}','800','500')" class="ml-5" style="text-decoration:none">
						<i class="Hui-iconfont">&#xe6e2;编辑</i>
					</a>
					<a title="删除" href="javascript:;" onclick="charge_del(this,'{$item.id}')" class="ml-5" style="text-decoration:none">
						<i class="Hui-iconfont">&#xe6e2;删除</i>
					</a>
				</td>
			</tr>
		{/foreach}
		</tbody>
	</table>
</div>
{include file="pub/footer"/}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
/*
	参数解释：
	title	标题
	url		请求的url
	id		需要操作的数据id
	w		弹出层宽度（缺省调默认值）
	h		弹出层高度（缺省调默认值）
*/
/*管理员-增加*/
function charge_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-删除*/
function charge_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url("Marketing/active_del")}',
			data:{id:id},
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

/*管理员-编辑*/
function charge_edit(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-停用*/
function charge_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		$.post("{:url('Marketing/chargeStatus')}", {id:id, status:0}, function(res){
		    if(res.code == 1){
                $(obj).parents("tr").find(".td-manage").prepend('<a onClick="charge_start(this,'+id+')" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;启用</i></a>');
                $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
                $(obj).remove();
                layer.msg('已停用!',{icon: 5,time:1000});
            }else{
		        layer.msg(res.msg);
			}
        });
	});
}

/*管理员-启用*/
function charge_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		$.post("{:url('Marketing/chargeStatus')}", {id:id, status:1}, function(res){
			if(res.code == 1){
                $(obj).parents("tr").find(".td-manage").prepend('<a onClick="charge_stop(this,'+id+')" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;停用</i></a>');
                $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                $(obj).remove();
                layer.msg('已启用!', {icon: 6,time:1000});
            }else{
			    layer.msg(res.msg);
			}
        });
	});
}
</script>
</body>
</html>